package com.hardson.demo.dao;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hardson.demo.mapper.UserMapper;

@Repository
public class BaseDaoImpl<T> extends SqlSessionDaoSupport implements BaseDao<T> {

	@Autowired
	private SqlSessionFactory sqlSessionFactory;
	
	@Autowired
	@Override
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){  
        super.setSqlSessionFactory(sqlSessionFactory);  
    } 
	
	@SuppressWarnings("unchecked")
	@Override
	public T selectByPrimaryKey(Long id, Class<?> clazz) {
	
		UserMapper userMapper = sqlSessionFactory.openSession().getMapper(UserMapper.class);
		return (T) userMapper.selectByPrimaryKey(id);
	}

	
}
